<?php
/**
 * Created by PhpStorm.
 * User: boye009
 * Date: 2016/4/8
 * Time: 9:17
 */

namespace Webview\Controller;

use Admin\Api\PostApi;
use Admin\Api\VPostInfoApi;
use Think\Controller;

class PostController extends Controller{

    public function viewPost(){
        $id = I('get.id',0);
        $from = I('get.from','');
        $map = array('id'=>$id);
        $result = apiCall(VPostInfoApi::GET_INFO,array($map));
        //dump($result);
        if(!$result['status']){
            $this->error($result['info']);
        }

        if(!$result['info']){
            $this->error('找不到相关内容!');
        }

        $share = 0;
        if($from == "app"){
            $share = 1;
        }

        $content = htmlspecialchars_decode($result['info']['post_content']);
        $title = $result['info']['post_title'];
        $this->assign("post",$result['info']);
        $this->assign("title",$title);
        $this->assign("content",$content);
        $this -> assign('share',$share);

        //@author 老胖子-何必都 <hebiduhebi@126.com>
        //查看次数+1
        $result = apiCall(PostApi::SET_INC,array(array('id'=>$id),'post_view',1));

        $this->display();
    }

    //@itboye010 zhouzhou
    //获取最新中奖结果公告 6059
    public function viewLottery(){
        $from = I('get.from','');
        $map = array(
            'post_category'=>6059,
        );
        $order = 'start_time desc';
        $result = apiCall(VPostInfoApi::GET_INFO,array($map,$order));
         //dump($result);
        if(!$result['status']){
            $this->error($result['info']);
        }

        if(!$result['info']){
            $this->error('找不到相关内容!');
        }

        $share = 0;
        if($from == "app"){
            $share = 1;
        }

        $content = htmlspecialchars_decode($result['info']['post_content']);
        $title = $result['info']['post_title'];
        $this->assign("post",$result['info']);
        $this->assign("title",$title);
        $this->assign("content",$content);
        $this -> assign('share',$share);

        //@author 老胖子-何必都 <hebiduhebi@126.com>
        //查看次数+1
        $result2 = apiCall(PostApi::SET_INC,array(array('id'=>$result['info']['id']),'post_view',1));

        $this->display('viewPost');
    }

    //@itboye010 zhouzhou
    //获取最新中奖活动公告 6058
    public function viewStart(){
        $from = I('get.from','');
        $map = array(
            'post_category'=>6058,
        );
        $order = 'start_time desc';
        $result = apiCall(VPostInfoApi::GET_INFO,array($map,$order));
         //dump($result);
        if(!$result['status']){
            $this->error($result['info']);
        }

        if(!$result['info']){
            $this->error('找不到相关内容!');
        }

        $share = 0;
        if($from == "app"){
            $share = 1;
        }

        $content = htmlspecialchars_decode($result['info']['post_content']);
        $title = $result['info']['post_title'];
        $this->assign("post",$result['info']);
        $this->assign("title",$title);
        $this->assign("content",$content);
        $this -> assign('share',$share);

        //@author 老胖子-何必都 <hebiduhebi@126.com>
        //查看次数+1
        $result2 = apiCall(PostApi::SET_INC,array(array('id'=>$result['info']['id']),'post_view',1));

        $this->display('viewPost');
    }
}